<?php defined('SYSPATH') or die('No direct script access.');

class Controller_Pages extends Controller_Common {

	public $template='layout/index';

	public function action_onePage() {
		$this->template->header=View::factory('pieces/header');

		$allCat = Model::factory('places')->getAll();

		foreach ($allCat as $item) {
			$allCatalog[$item['parent_id']][] = $item;
		}

		$menu = Model::factory('menu')->getMenu();

		$this->template->leftContent=View::factory('pieces/left_content', array(
			'catalog' => Model::factory('places')->get_countries(),
			'menu' => $menu
		));

		$link=$this->request->param('link');
		$page=Model::factory('pages')->onePage($link);

		if (count($page)==0)
			throw new HTTP_Exception_404(':page does not exist', array(':page' => 'Gaia'));

		$rightContent=View::factory('pages/onePage', array(
			'page' => $page
		));

		$this->template->title.=' - '.$page[0]['title'];
		$this->template->rightContent=$rightContent;

        $this->template->footer=View::factory('pieces/footer', array(
            'menu' => $menu
        ));
	}
}